package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.AfVessel;
import com.ruoyi.security.domain.vo.AfVesselVo;
import com.ruoyi.security.service.IAfVesselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 压力容器台账Controller
 *
 * @author Felix
 * @date 2021-10-12
 */
@Api(tags = " 压力容器台账")
@RestController
@RequestMapping("/afVessel")
public class AfVesselController extends BaseController {
    @Autowired
    private IAfVesselService afVesselService;

    /**
     * 查询压力容器台账列表
     */
    @ApiOperation(value = "查询压力容器台账列表", notes = "查询压力容器台账列表")
    @PreAuthorize(hasPermi = "security:afVessel:list")
    @GetMapping("/list")
    public TableDataInfo list(AfVessel afVessel) {
        startPage();
        List<AfVessel> list = afVesselService.selectAfVesselList(afVessel);
        return getDataTable(list);
    }


    /**
     * 小程序查询压力容器台账列表
     */
    @ApiOperation(value = "小程序查询压力容器台账列表", notes = "小程序查询压力容器台账列表")
    @PreAuthorize(hasPermi = "security:afVessel:list")
    @GetMapping("/appList")
    public AjaxResult appList(AfVesselVo vo) {
        AfVessel query = new AfVessel();
        BeanUtils.copyProperties(vo, query);
        List<AfVessel> list = afVesselService.selectAfVesselList(query);
        List<AfVesselVo> result = new ArrayList<>();
        list.stream().forEach(o -> {
            AfVesselVo v = new AfVesselVo();
            BeanUtils.copyProperties(o, v);
            result.add(v);
        });
        return AjaxResult.success(result);
    }


    /**
     * 导出压力容器台账列表
     */
    @ApiOperation(value = "导出压力容器台账列表", notes = "导出压力容器台账列表")
    @PreAuthorize(hasPermi = "security:afVessel:export")
    @Log(title = "压力容器台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfVessel afVessel) throws IOException {
        List<AfVessel> list = afVesselService.selectAfVesselList(afVessel);
        ExcelUtil<AfVessel> util = new ExcelUtil<AfVessel>(AfVessel.class);
        util.exportExcel(response, list, "压力容器台账数据");
    }

    /**
     * 获取压力容器台账详细信息
     */
    @ApiOperation(value = "获取压力容器台账详细信息", notes = "获取压力容器台账详细信息")
    @PreAuthorize(hasPermi = "security:afVessel:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afVesselService.selectAfVesselById(id));
    }

    /**
     * 新增压力容器台账
     */
    @ApiOperation(value = "新增压力容器台账", notes = "新增压力容器台账")
    @PreAuthorize(hasPermi = "security:afVessel:add")
    @Log(title = "压力容器台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfVessel afVessel) {
        return toAjax(afVesselService.insertAfVessel(afVessel));
    }

    /**
     * 修改压力容器台账
     */
    @ApiOperation(value = "修改压力容器台账", notes = "修改压力容器台账")
    @PreAuthorize(hasPermi = "security:afVessel:edit")
    @Log(title = "压力容器台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfVessel afVessel) {
        return toAjax(afVesselService.updateAfVessel(afVessel));
    }

    /**
     * 删除压力容器台账
     */
    @ApiOperation(value = "删除压力容器台账", notes = "删除压力容器台账")
    @ApiImplicitParam(name = "ids", value = "压力容器台账ID数组", required = true, paramType = "path", allowMultiple = true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afVessel:remove")
    @Log(title = "压力容器台账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afVesselService.deleteAfVesselByIds(ids));
    }
}
